﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows;
using System.Windows.Forms;

namespace luanvanFinal
{
    class clsVersion
    {
        int idProject;
        String idReq;
        String vClass;
        
        public String IdReq
        {
            get { return idReq; }
            set { idReq = value; }
        }
        public int IdProject
        {
            get { return idProject; }
            set { idProject = value; }
        }
        public String VClass
        {
            get { return vClass; }
            set { vClass = value; }
        }
        

        public clsVersion()
        {
            idProject = 0;
            idReq = "";
            vClass = "";
            
        }

        public void insertVersion()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("insertVersion", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.Parameters.Add("@idReq", SqlDbType.NVarChar).Value = this.idReq;
                sqlcmd.Parameters.Add("@class", SqlDbType.NVarChar).Value = this.vClass;
                
                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }

        public void deleteversionByIdProject()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("deleteversionByIdProject", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                //sqlcmd.Parameters.Add("@idReq", SqlDbType.NVarChar).Value = this.idReq;
                //sqlcmd.Parameters.Add("@class", SqlDbType.NVarChar).Value = this.vClass;

                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }
        public void deleteversionByIdReq()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("deleteversionByIdReq", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.Parameters.Add("@idReq", SqlDbType.NVarChar).Value = this.idReq;
                //sqlcmd.Parameters.Add("@class", SqlDbType.NVarChar).Value = this.vClass;

                sqlcmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }

        public DataTable getDataVersion(String strSQL)
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            SqlDataAdapter da = new SqlDataAdapter(strSQL, ketnoi.Connection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            ketnoi.closeConnection();
            return dt;
        }

       
    }
}
